<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class LaborAttendance extends Model
{
    use HasFactory;

    protected $fillable = [
        'project_id',
        'company_id',
        'team_id',
        'labor_company_id',
        'labor_id',
        'attendance_date',
        'in_time',
        'out_time',
        'work_hours',
        'floor',
        'area',
        'ip',
        'situation',
        'status',
        'delay_minutes',
        'early_leave_minutes',
        'remark'

    ];
    const POSTONLY = [
        'project_id',
        'company_id',
        'team_id',
        'labor_company_id',
        'labor_id',
        'attendance_date',
        'in_time',
        'out_time',
        'work_hours',
        'floor',
        'area',
        'ip',
        'situation',
        'status',
        'delay_minutes',
        'early_leave_minutes',
        'remark'
    ];

    protected function serializeDate(\DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    public function project()
    {
        return $this->belongsTo(Project::class)->select('id','name','number','item_number','item_name');
    }

    public function team()
    {
        return $this->belongsTo(LaborTeam::class)->select('id','name','number');
    }

    public function labor()
    {
        return $this->belongsTo(Labor::class)->select('id','name','mobile');
    }
}
